package com.tn.tgt.easybuy.web;

import com.tn.tgt.easybuy.model.EbUser;
import com.tn.tgt.easybuy.service.EbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private EbUserService ebUserService;

    @RequestMapping("/to_login")
    public  String toLogin(HttpSession session){

        return "login";

    }
    @RequestMapping("/login")
    public String login(HttpSession session, EbUser ebUser){
        System.out.println("=========="+ebUser);
        EbUser lgnUser = ebUserService.login(ebUser);
        if(lgnUser==null){
            session.setAttribute("msg","用户名或者密码错误，请重新登录");
            return "redirect:/login/to_login";
        }
        session.removeAttribute("msg");
        session.setAttribute("lgnUserName",lgnUser.getEuUserName());
        return "redirect:/front/index";}

        @RequestMapping("/logout")
        public  String logout(HttpSession session){
            session.removeAttribute("lgnUserName");
            return  "redirect:/front/index";
        }
    }


